package com.suep.business.mapper;

import com.suep.business.domain.MealCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*
* 注意，这里与Meal是有级联删除关系的
* */

@Mapper
public interface MealCategoryMapper {
    /**
     * 根据ID查询菜品分类
     */
    @Select("SELECT * FROM meal_category WHERE category_id = #{categoryId}")
    MealCategory selectById(Integer categoryId);

    /**
     * 查询所有菜品分类
     */
    @Select("SELECT * FROM meal_category")
    List<MealCategory> selectAll();

    /**
     * 根据店铺ID查询菜品分类
     */
    @Select("SELECT * FROM meal_category WHERE store_id = #{storeId}")
    List<MealCategory> selectByStoreId(Integer storeId);



    /**
     * 插入菜品分类
     */
    @Insert("INSERT INTO meal_category(name, sort_order, is_available, store_id, created_at, updated_at) " +
            "VALUES(#{name}, #{sortOrder}, #{isAvailable}, #{storeId}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "categoryId")
    int insert(MealCategory mealCategory);

    /**
     * 更新菜品分类
     */
    @Update("UPDATE meal_category SET name=#{name}, sort_order=#{sortOrder}, is_available=#{isAvailable}, " +
            "updated_at=#{updatedAt} WHERE category_id=#{categoryId}")
    int update(MealCategory mealCategory);

    /**
     * 根据ID删除菜品分类
     */
    @Delete("DELETE FROM meal_category WHERE category_id=#{categoryId}")
    int deleteById(Integer categoryId);

    /**
     * 根据店铺ID删除菜品分类
     */
    @Delete("DELETE FROM meal_category WHERE store_id=#{storeId}")
    int deleteByStoreId(Integer storeId);
}
